
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 06/01/2015 03:11:12
-- Generated from EDMX file: C:\Users\USUARIO\Documents\Visual Studio 2012\Projects\ws-sismun\ws-sismun\Model1.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [sismun];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_SectorSubSector]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[SubSectorSet] DROP CONSTRAINT [FK_SectorSubSector];
GO
IF OBJECT_ID(N'[dbo].[FK_VecinoSector_Vecino]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[VecinoSector] DROP CONSTRAINT [FK_VecinoSector_Vecino];
GO
IF OBJECT_ID(N'[dbo].[FK_VecinoSector_Sector]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[VecinoSector] DROP CONSTRAINT [FK_VecinoSector_Sector];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[VecinoSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[VecinoSet];
GO
IF OBJECT_ID(N'[dbo].[SubSectorSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[SubSectorSet];
GO
IF OBJECT_ID(N'[dbo].[SectorSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[SectorSet];
GO
IF OBJECT_ID(N'[dbo].[VecinoSector]', 'U') IS NOT NULL
    DROP TABLE [dbo].[VecinoSector];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'VecinoSet'
CREATE TABLE [dbo].[VecinoSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Nombre] nvarchar(max)  NOT NULL,
    [NroDocumento] nvarchar(max)  NOT NULL,
    [TipoDocumento] nvarchar(max)  NOT NULL,
    [Direccion] nvarchar(max)  NOT NULL,
	[Correo] nvarchar(max)  NULL
);
GO

-- Creating table 'SubSectorSet'
CREATE TABLE [dbo].[SubSectorSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Descripcion] nvarchar(max)  NOT NULL,
    [SectorId] int  NOT NULL
);
GO

-- Creating table 'SectorSet'
CREATE TABLE [dbo].[SectorSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Descripcion] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'VecinoSector'
CREATE TABLE [dbo].[VecinoSector] (
    [Vecino_Id] int  NOT NULL,
    [Sector_Id] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'VecinoSet'
ALTER TABLE [dbo].[VecinoSet]
ADD CONSTRAINT [PK_VecinoSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'SubSectorSet'
ALTER TABLE [dbo].[SubSectorSet]
ADD CONSTRAINT [PK_SubSectorSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'SectorSet'
ALTER TABLE [dbo].[SectorSet]
ADD CONSTRAINT [PK_SectorSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Vecino_Id], [Sector_Id] in table 'VecinoSector'
ALTER TABLE [dbo].[VecinoSector]
ADD CONSTRAINT [PK_VecinoSector]
    PRIMARY KEY NONCLUSTERED ([Vecino_Id], [Sector_Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [SectorId] in table 'SubSectorSet'
ALTER TABLE [dbo].[SubSectorSet]
ADD CONSTRAINT [FK_SectorSubSector]
    FOREIGN KEY ([SectorId])
    REFERENCES [dbo].[SectorSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_SectorSubSector'
CREATE INDEX [IX_FK_SectorSubSector]
ON [dbo].[SubSectorSet]
    ([SectorId]);
GO

-- Creating foreign key on [Vecino_Id] in table 'VecinoSector'
ALTER TABLE [dbo].[VecinoSector]
ADD CONSTRAINT [FK_VecinoSector_Vecino]
    FOREIGN KEY ([Vecino_Id])
    REFERENCES [dbo].[VecinoSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [Sector_Id] in table 'VecinoSector'
ALTER TABLE [dbo].[VecinoSector]
ADD CONSTRAINT [FK_VecinoSector_Sector]
    FOREIGN KEY ([Sector_Id])
    REFERENCES [dbo].[SectorSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_VecinoSector_Sector'
CREATE INDEX [IX_FK_VecinoSector_Sector]
ON [dbo].[VecinoSector]
    ([Sector_Id]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------